package com.a1anwang.okble.client.core;

import java.util.HashMap;

/**
 * Created by a1anwang.com on 2018/5/24.
 */

public class OKBLEOperationFailedDescUtils {

    private static HashMap<Integer, String> descArray = new HashMap<>();
    private static final int CONNECTION_PRIORITY_BALANCED = 0;
    private static final int CONNECTION_PRIORITY_HIGH = 1;
    private static final int CONNECTION_PRIORITY_LOW_POWER = 2;
    private static final int GATT_CONNECTION_CONGESTED = 143;
    private static final int GATT_FAILURE = 257;
    private static final int GATT_INSUFFICIENT_AUTHENTICATION = 5;
    private static final int GATT_INSUFFICIENT_ENCRYPTION = 15;
    private static final int GATT_INVALID_ATTRIBUTE_LENGTH = 13;
    private static final int GATT_INVALID_OFFSET = 7;
    private static final int GATT_READ_NOT_PERMITTED = 2;
    private static final int GATT_REQUEST_NOT_SUPPORTED = 6;
    private static final int GATT_SUCCESS = 0;
    private static final int GATT_WRITE_NOT_PERMITTED = 3;

    static {
        descArray.put(GATT_READ_NOT_PERMITTED, "GATT read operation is not permitted");
        descArray.put(GATT_WRITE_NOT_PERMITTED, "GATT write operation is not permitted");
        descArray.put(GATT_INSUFFICIENT_AUTHENTICATION, "Insufficient authentication for a given operation");
        descArray.put(GATT_REQUEST_NOT_SUPPORTED, "The given request is not supported");
        descArray.put(GATT_INSUFFICIENT_ENCRYPTION, "Insufficient encryption for a given operation");
        descArray.put(GATT_INVALID_OFFSET, "A read or write operation was requested with an invalid offset");
        descArray.put(GATT_INVALID_ATTRIBUTE_LENGTH, "A write operation exceeds the maximum length of the attribute");
        descArray.put(GATT_CONNECTION_CONGESTED, "A remote device connection is congested");
        descArray.put(GATT_FAILURE, "A GATT operation failed");
        descArray.put(0x0b, "value length is more than mtu size");
    }

    /**
     * 获取Desc
     *
     * @param errCode 错误码
     * @return string
     */
    public static String getDesc(int errCode) {
        return descArray.getOrDefault(errCode, "unknown error");
    }
}
